package de.hauck.rtmidlet.model;

import java.util.Date;

import de.hauck.rtmidlet.utils.MyLogger;
import de.hauck.rtmidlet.utils.Utils;

/**
 * JavaBean for stocks
 * 
 * @author Achim Hauck
 */
public class StockBean {
	
	private String name;
	private String symbol_rt;
	private String symbol_ts;
	private String symbol_yahoo;
	private String symbol_ft;
	private String amount;
	private String invest;
	private Date buyDate;
	private boolean[] displayFlags;
	
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name=name;
	}

	public String getSymbolRT() {
		return this.symbol_rt;
	}

	public void setSymbolRT(String symbol_rt) {
		this.symbol_rt = symbol_rt;
	}

	public String getSymbolTS() {
		return this.symbol_ts;
	}

	public void setSymbolTS(String symbol_ts) {
		this.symbol_ts = symbol_ts;
	}

	public String getSymbolYahoo() {
		return this.symbol_yahoo;
	}

	public void setSymbolYahoo(String symbol_yahoo) {
		this.symbol_yahoo = symbol_yahoo;
	}
	
	public String getSymbolFt() {
		return this.symbol_ft;
	}

	public void setSymbolFt(String symbol_ft) {
		this.symbol_ft = symbol_ft;
	}

	public String getAmount() {
		return this.amount;
	}

	public void setAmount(String amount) {
		this.amount = amount;
	}

	public String getInvest() {
		return this.invest;
	}

	public void setInvest(String invest) {
		this.invest = invest;
	}

	public Date getBuyDate() {
		return buyDate;
	}

	public void setBuyDate(Date buyDate) {
		this.buyDate = buyDate;
	}

	public boolean[] getDisplayFlags() {
		return this.displayFlags;
	
	}

	public void setDisplayFlags(boolean[] displayFlags) {
		this.displayFlags = displayFlags;
	}

	/**
	 * This constructor creates a new JavaBean with given arguments
	 * 
	 * @return
	 */
	public StockBean(String name, String symbol_rt, String symbol_ts,
			String symbol_yahoo, String symbol_ft, String amount, String invest, Date buyDate,
			boolean[] displayFlags) {
		this.name = name;
		this.symbol_rt = symbol_rt;
		this.symbol_ts = symbol_ts;
		this.symbol_yahoo = symbol_yahoo;
		this.symbol_ft = symbol_ft;
		this.amount = amount;
		this.invest = invest;
		this.buyDate = buyDate;
		this.displayFlags = displayFlags;
	}

	public StockBean() {
		
	}
	
	/**
	 * setToken sets the fields/token of a StockBean dependent from their position i.
	 * 0: sets Name
	 * 1: sets Symbol RT
	 * 2: sets Symbol TS
	 * 3: sets Symbol Yahoo
	 * 4: sets symbol FT
	 * 5: sets amount
	 * 6: sets investment
	 * 7: sets buy date
	 * 8: sets display flags
	 *
	 */
	public void setToken(int i, String token) {
		switch (i){
		case 0: setName(token); break;
		case 1: {
			setSymbolRT(token);
			break;
		}
		case 2: setSymbolTS(token); break;
		case 3: setSymbolYahoo(token); break;
		case 4: setSymbolFt(token); break;
		case 5: { 
			setAmount(token);
			break;
		}
		case 6: {
			setInvest(token);
			break;
		}
		case 7: setBuyDate(Utils.convertString2Date(token)); break;
		case 8: setDisplayFlags(Utils.convertString2DisplayFlags(token)); break;
		
		}
	}
	
	public void printBean() {
		MyLogger.debug("Bean: [\""+name+"\", "+
				"\""+symbol_rt+"\", "+
				"\""+symbol_ts+"\", "+
				"\""+symbol_yahoo+"\", "+
				"\""+symbol_ft+"\", "+
				"\""+amount+"\", "+
				"\""+invest+"\", "+
				"\""+Utils.convertDate2String(buyDate)+"\", "+
				"\""+Utils.convertDisplayFlags2String(displayFlags)+"\"]");
	}

	public int compareTo(Object o) {
		return name.toUpperCase().compareTo(((StockBean)o).getName().toUpperCase());
	}

}
